<template>
  <div class="myContainer">
    <!-- 头部标题 start -->  
    <el-row class="myHeadeTitle">
      <el-col :span="18" class="myLineHeight_35px">
        维保计划模板管理
      </el-col>
      <el-col :span="6" class="myTextAlignRight">
        <el-button class="myBgGreen" @click="onAdd" v-if="isShow(230)">新增</el-button>
        <!-- <el-button class="myBgGreen">导出</el-button> -->
      </el-col>
    </el-row>
    <!-- 头部标题 end -->
    <!-- 搜索部分 start -->
    <el-row :gutter="10">
      <el-col :span="6">
        <template>
          <el-select v-model="modelValue" clearable placeholder="全部计划模板对象模型">
            <el-option
              v-for="item in modelOptions"
              :key="item.id"
              :label="item.targetname"
              :value="item.id">
            </el-option>
          </el-select>
        </template>
      </el-col>
      <el-col :span="6">
        <el-input placeholder="输入关键字进行查询" clearable v-model="kw"></el-input>
      </el-col>
      <el-col :span="6">
        <el-button class="myBgGreen" @click="onSearchKW">查询</el-button>
      </el-col>
    </el-row>
    <!-- 搜索部分 end -->
    <!-- 数据列表 start -->
    <div class="myPaddingTop_10px">
      <template>
        <el-table
          :data="tableDataList"
          border
          stripe
          v-loading="loading"
          @selection-change="handleSelectionChange"
          style="width: 100%">
          <!-- <el-table-column
            type="selection"
            width="100">
          </el-table-column> -->
          <el-table-column
            type="index"
            label="序号"
            width="100">
          </el-table-column>
          <el-table-column
            prop="id"
            width="160"
            label="计划模板编号">
          </el-table-column>
          <el-table-column
            prop="name"
            label="计划模板名称">
          </el-table-column>
          <el-table-column
            prop="typename"
            label="计划模板对象类型">
          </el-table-column>
          <el-table-column
            prop="cycle"
            width="120"
            label="计划模板周期">
          </el-table-column>
          <el-table-column
            prop="frequency"
            width="120"
            label="计划模板频次">
          </el-table-column>
          <el-table-column
            prop="status"
            width="100"
            label="状态">
            <template scope="scope">
              <span>{{scope.row.status| isUsableText}}</span>
            </template>
          </el-table-column>
          <el-table-column
            width="100"
            label="操作">
            <template scope="scope">
              <el-button class="look" type="text" size="small" @click="onGetDetail(scope.row.id)">查看</el-button> |
              <el-button class="look" type="text primary" size="small" @click="onEdit(scope.row.id)" v-if="isShow(231)">编辑</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </div>
    <!-- 数据列表 end -->
    <!-- 分页控件 start -->
    <div class="block">                    
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page_num"
        :page-sizes="[10, 15]"
        :page-size="page_size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <!-- 分页控件 end -->
  </div>
</template>  

<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myHeadeTitle{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    padding-bottom: 5px;
    border-bottom: 1px solid #dbdbdb;
    margin-bottom:10px; 
  }
  .myHeadeTitle:before,.myHeadeTitle:after{
    content: " ";
    display: block;
    clear: both;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top: 2px;
  }
  .myLineHeight_35px{
    line-height: 35px;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myPaddingTop_10px{
    padding-top: 10px;
  }
</style>

<script>
  import { getModelManageList , GetModelObjList , isUsable } from '@/api/maintenanceplan';
  export default {
     data(){
      return{
        modelOptions:"",
        modelValue:"",
        tableDataList:[],//数据列表
        page_size:10,
        page_num:1,
        total:null,
        kw:"",
        isUsable:isUsable,
        loading:false
      }
    },
    components: {
       
    },
    filters: {
      isUsableText: function(value) {
        return isUsable[value];
      }
    },
    mounted(){
      document.title = '计划模板管理';
      this.onGetModelManageList();
      this.onGetModelObjList();
    },
    methods:{
      onGetModelManageList(){//获取维保计划模板列表
        let vm=this;
        vm.loading=true;
        const params = {
          target_typeid:vm.modelValue,
          keyword:vm.kw,
          page_num: vm.page_num,
          page_size: vm.page_size
        };
        // console.log(params)
        getModelManageList(params)
        .then(response => {
          let res = response.data;
          vm.tableDataList = res.rows;
          vm.total = res.total;
          vm.page_num = res.page_num;
          vm.page_size = res.page_size;
          vm.loading=false;
          // console.log("列表数据",vm.tableDataList)
        }).catch(error => {
          vm.loading=false;
          console.log("列表数拉取失败",error);
        })
      },
      onGetModelObjList(){//获取维保对象类型
        let vm=this;
        const params = {
          type:"",
          page_num: vm.page_num,
          page_size: vm.page_size
        }; 
        GetModelObjList(params)
        .then(response => {
          let res = response.data;
          vm.modelOptions = res.rows;
          // console.log("模板对象类型",vm.modelOptions)
        }).catch(error => {
          
        })
      },
      handleSelectionChange(val) {//添加表格复选框【全选等功能】
        
      },
      handleSizeChange(val) {//每页条数控制
        this.page_size = val;
        this.onGetModelManageList();
      },
      handleCurrentChange(val) {//每页
        this.page_num = val;
        this.onGetModelManageList();
      },
      onGetDetail:function(id){//详情查看
        this.$router.push({
          path:'/wbjhmbglComonents',
          query: {type: 'info', id: id}
        })
      },
      onSearchKW:function(){//关键词搜索
        this.onGetModelManageList();
      },
      onEdit:function(id){//编辑
        this.$router.push({
          path:'/wbjhmbglComonents',
          query: {type: 'update', id: id}
        })
      },
      onAdd(){//新增
        this.$router.push({
          path:'/wbjhmbglComonents',
          query: {type: 'add'}
        })
      }
    }
  }

</script>  



